package cn.stylefeng.guns.wrapper;

import cn.stylefeng.guns.sys.core.constant.factory.ConstantFactory;
import cn.stylefeng.guns.sys.core.util.DecimalUtil;
import cn.stylefeng.guns.sys.modular.system.mapper.UserMapper;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import cn.stylefeng.roses.core.base.warpper.BaseControllerWrapper;
import cn.stylefeng.roses.kernel.model.page.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jdk.nashorn.internal.runtime.linker.LinkerCallSite;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;
//将创建者和修改者的ID处理为名称
public class MyWrapper extends BaseControllerWrapper {

    @Autowired
    UserService UserService;

    public MyWrapper(Map<String, Object> single) {
        super(single);
    }

    public MyWrapper(List<Map<String, Object>> multi) {
        super(multi);
    }

    public MyWrapper(Page<Map<String, Object>> page) {
        super(page);
    }

    public MyWrapper(PageResult<Map<String, Object>> pageResult) {
        super(pageResult);
    }

    @Override
    public <T> T wrap() {
        return super.wrap();
    }

    @Override
    protected void wrapTheMap(Map<String, Object> map) {
        Long creater = DecimalUtil.getLong(map.get("createUser"));
        map.put("createrName", ConstantFactory.me().getUserNameById(creater));
        Long update = DecimalUtil.getLong(map.get("updateUser"));
        map.put("updateName", ConstantFactory.me().getUserNameById(update));
    }
}
